<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE>
<html>
<head>
<meta charset=UTF-8>
<title></title>
<script src="${webroot }js/jquery.min.js"></script>
<script src="${webroot }js/bootstrap.min.js"></script>
<link rel="stylesheet" href="${webroot }css/bootstrap.min.css">
<link rel="stylesheet" href="${webroot }css/common.css">
<link rel="stylesheet" href="${webroot }css/client.css">
<script src="${webroot }js/func.action.js"></script>
<script src="${webroot }js/web.config.js"></script>
</head>
<body>
  <table class="table">
    <caption><a data-toggle="modal" data-target="#myModal">添加管理员</a></caption>
    <thead>
      <tr>
      	<td>编号</td>
        <td>账号</td>
        <td>显示名</td>
        <td>操作</td>
      </tr>
    </thead>
    <tbody>
      <c:forEach items="${list }" var="ad">
      <tr>
      	<td>${ad.adminId }</td>
      	<td>${ad.adminCode }</td>
      	<td>${ad.adminName }</td>
      	<td>
      	  <c:if test="${ad.adminStatus == 1 }">
      	    <a href="#" onclick="updateAdminStatus(${ad.adminId},2)">禁用</a>	
      	  </c:if>
      	  <c:if test="${ad.adminStatus == 2 }">
      	    <a href="#" onclick="updateAdminStatus(${ad.adminId},1)">启用</a>	
      	  </c:if>
      	</td>
      </tr>
      </c:forEach>
    </tbody>
  </table>
  <div class="info_footer">
  <div class="footer_con">
  <div class="btn-group dropup info_choose ">
    <span class="dropdown-toggle" id="status_menu" role="0" data-toggle="dropdown">
      <c:if test="${status <= 0 }">
      	全部类型
      </c:if>
      <c:if test="${status == 1 }">
      	激活
      </c:if>
      <c:if test="${status == 2 }">
      	禁用
      </c:if>
    </span><span class="caret"></span>
    <ul class="dropdown-menu" role="menu" id="status_item">
      <li>
        <a role="0" href="${webroot }web/admin/query?status=0">全部类型</a>
      </li>
      <li>
        <a role="1" href="${webroot }web/admin/query?status=1">激活状态</a>
      </li>
      <li>
        <a role="2" href="${webroot }web/admin/query?status=2">禁用状态</a>
      </li>
    </ul>
  </div>
  </div>
  </div>
  
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" 
               data-dismiss="modal" aria-hidden="true">
                  &times;
            </button>
            <h4 class="modal-title" id="myModalLabel">添加管理员</h4>
         </div>
         <div class="modal-body">
           <div class="form-group">
             <label class="login_label">账号：</label>
             <input class="form-control login_input" type="text" 
               placeholder="请输入账号" name="adminCode">
           </div>
           <div class="form-group">
             <label class="login_label">显示名：</label>
             <input class="form-control login_input" type="text" 
               placeholder="请输入显示名" name="adminName">
           </div>
           <div class="form-group">
             <label class="login_label">密码：</label>
             <input class="form-control login_input" type="password" 
               placeholder="请输入密码" name="adminPass">
           </div>
         </div>
         <div class="modal-footer">
         	<span id="res_msg"></span>
            <button type="button" class="btn btn-default" 
               data-dismiss="modal">关闭</button>
            <button type="button" id="add_admin" class="btn btn-primary">确认添加</button>
         </div>
      </div><!-- /.modal-content -->
  </div><!-- /.modal -->
  
  <script type="text/javascript">
    $(document).ready(function(){
    	$("#add_admin").click(function(){
    		var code = $("[name='adminCode']").val();
    		var name = $("[name='adminName']").val();
    		var pass = $("[name='adminPass']").val();
    		if(code != "" && name != "" && pass != ""){
    			$.ajax({
    				url : webRoot + "web/admin/add",
    				type : "post",
    				dataType : "json",
    				data : {
    					"adminCode":code,
    					"adminName":name,
    					"adminPass":pass
    				},
    				success:function(data){
    					if(data.result == "success"){
    						alert("添加成功！");
    						$('#myModal').modal('hide');
    						location.reload();
    					}else{
    						alert("添加失败！");
    					}
    				}
    			});
    		}
    	});
    });
  </script>
  
</body>
</html>